<html>
<head><meta charset="utf-8"><title>ty::List StableHash · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html">ty::List StableHash</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="202795519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/ty%3A%3AList%20StableHash/near/202795519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html#202795519">(Jul 03 2020 at 11:53)</a>:</h4>
<p>I noticed that we're currently hashing both the pointer and the length of ty::List in it's <a href="https://github.com/rust-lang/rust/blob/f844ea1e561475e6023282ef167e76bc973773ef/src/librustc_middle/ich/impls_ty.rs#L14">StableHash impl</a> for the cache of hashes. It's unclear to me why this is necessary, though, as ty::List doesn't support subslicing (and indeed the Hash/PartialEq impls don't check the length).</p>
<p><a href="https://github.com/rust-lang/rust/pull/47373#issuecomment-357216336">This comment</a> implies that this is to "stay on the safe side" -- but it seems like an odd thing to do? I was also thinking that we could allocate a u128 space in front of every ty::List allocation and store the stable hash there (using atomic load/stores), to potentially save some time on checking the hashmap for every StableHash</p>



<a name="202795541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/ty%3A%3AList%20StableHash/near/202795541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html#202795541">(Jul 03 2020 at 11:53)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="120989">@Nicholas Nethercote</span></p>



<a name="202795614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/ty%3A%3AList%20StableHash/near/202795614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html#202795614">(Jul 03 2020 at 11:54)</a>:</h4>
<p>For the cache alteration I guess it depends on if we expect only a small percentage of ty::List's to get stable hashed. But I think that's not the case today?</p>



<a name="202822348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/ty%3A%3AList%20StableHash/near/202822348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html#202822348">(Jul 03 2020 at 16:56)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> storing the hash as part of an interned "object" was something I've been thinking for a while, especially in the context of partially duplicated interners (across threads) but I don't think I ever explicitly proposed it because it was a part of a much more drastic change in how we do interning and comparisons</p>



<a name="202822369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/ty%3A%3AList%20StableHash/near/202822369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html#202822369">(Jul 03 2020 at 16:57)</a>:</h4>
<p>the equation changes if we do it for <code>StableHash</code> instead of messing with the interning scheme</p>



<a name="202822371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/ty%3A%3AList%20StableHash/near/202822371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html#202822371">(Jul 03 2020 at 16:57)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="116009">@nikomatsakis</span></p>



<a name="202822400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/ty%3A%3AList%20StableHash/near/202822400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html#202822400">(Jul 03 2020 at 16:57)</a>:</h4>
<p>Yeah I was thinking just for the stable hash</p>



<a name="202822477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/ty%3A%3AList%20StableHash/near/202822477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html#202822477">(Jul 03 2020 at 16:58)</a>:</h4>
<p>it would be nice if we had known-good-but-relatively-cheap way to handle "hashing hashes" (ideally better than the naive thing, but maybe that works great? unsure) and use that instead of hashing pointers or hashing the entire value, recursively, every time</p>



<a name="202848734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/ty%3A%3AList%20StableHash/near/202848734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html#202848734">(Jul 04 2020 at 00:45)</a>:</h4>
<p>Well so the results came back and it looks like it had no effect pretty much</p>



<a name="202848743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/ty%3A%3AList%20StableHash/near/202848743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html#202848743">(Jul 04 2020 at 00:45)</a>:</h4>
<p>I'm mildly surprised by that</p>



<a name="202848744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/ty%3A%3AList%20StableHash/near/202848744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html#202848744">(Jul 04 2020 at 00:45)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/73991">https://github.com/rust-lang/rust/pull/73991</a></p>



<a name="202848791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/ty%3A%3AList%20StableHash/near/202848791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/ty.3A.3AList.20StableHash.html#202848791">(Jul 04 2020 at 00:46)</a>:</h4>
<p>but I guess this also implies that caching the hash directly in the ty::List vs TLS probably isn't really worth it</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>